/**
 *	bbx 
 */
define(function(require, exports, module) {
	"use strict";
	//每一个页面都要引入的工具类
	var CommonTools = require('CommonTools_Core');

	//页面跳转管理类
	var WindowTools = require('WindowTools_Core');
	var studyLogs = require('StudyLogs_Service');
	//每一个页面都要引入的工具类
	// initready 要在所有变量初始化做完毕后
	CommonTools.initReady(initData);
	/**
	 * @description 初始化数据,结合initReady使用
	 * plus情况为plusready
	 * 其它情况为直接初始化
	 */
	function initData() {
		//引入必备文件,下拉刷新依赖于mui与mustache
		CommonTools.importFile([
			'js/libs/mui.min.js',
			'js/libs/mui.picker.min.js'
		], function() {
			console.log("init");
			mui.init({
				statusBarBackground: '#f7f7f7'
			});
			WindowTools.preloadTemplate();
			init();
		});
	}
	
	/**
	 *@description 日期选择 
	 */
	function showDataPicker() {
//		mui('.mui-content').on('tap', '#timepicker', function() {
//			console.log("car exe");
//			var dtPicker = new mui.DtPicker({
//				type:'date'
//			});
//			dtPicker.show(function(selectItems) {
//				console.log(selectItems.y); //{text: "2016",value: 2016} 
//				console.log(selectItems.m); //{text: "05",value: "05"} 
//				debugger;
////				selectItems.text;
//				document.getElementById('timepicker').innerHTML = selectItems.text;
//				updateTimeSelect();
//			})
//		});
	}
	
	function updateTimeSelect(){
		var data = {
			'PlaceID' : uploadPlace,
			'TimeSoltType' : uploadTimeStyle,
			'CourseType' : uploadCourseStyle,
			'CoachID' : uploadTeacher,
			'Date' : uploadDate
		}
		studyLogs.canusetime(data,function(res){
			var hourSelect = document.getElementById('hourSelect');
			var allItem ='';
			for(var i = res.startTime ; i < res.endTime ; i++){
				allItem += '<input type="checkbox" name="time" id="time'+i+'" value="'+i+'" /><label for="time'+i+'">'+i+'点</label>'
			}
			hourSelect.innerHTML = allItem;
		});
	}

	function init() {
		showDataPicker();
		getStudyTime();
	}
	
	var uploadPlace;
	var uploadTimeStyle;
	var uploadCourseStyle;
	var uploadTeacher;
	var uploadDate;
	
	function getStudyTime(){
		var places = document.getElementById('places');
		uploadPlace = places.options[places.selectedIndex].value;
		places.addEventListener('change',function(e){
			var val = this.options[this.selectedIndex].value;
			console = val;
		});
		var studyTime = document.getElementById('studyTime');
		uploadTimeStyle = studyTime.options[studyTime.selectedIndex].value;
		studyTime.addEventListener('change',function(e){
			var val = this.options[this.selectedIndex].value;
			console.log(val);
		});
		var course = document.getElementById('course');
		uploadCourseStyle = course.options[course.selectedIndex].value;
		course.addEventListener('change',function(e){
			var val = this.options[this.selectedIndex].value;
			console.log(val);
		});
		var teacher = document.getElementById('teacher');
		uploadTeacher = teacher.options[teacher.selectedIndex].value;
		teacher.addEventListener('change',function(e){
			var val = this.options[this.selectedIndex].value;
			console.log(val);
		});
	}

});